package com.atguigu.controller;

import com.atguigu.pojo.Employee;
import com.atguigu.pojo.Student;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

@Controller
public class AjaxHandler {
    @ResponseBody //让 handler 方法的返回值本身就是当前请求的响应数据。不再参考视图处理器中配置的前后缀信息。
    @RequestMapping("/get/emp/by/ajax")
    public Employee getEmployeeByAjax() {
        return new Employee(555, "empName555", 555.55);
    }

    @ResponseBody
    @RequestMapping("/send/array/plan/one.html")
    public String one(@RequestParam("empIdArray[]") Integer[] empIdArray) {
        for(int i=0;i<empIdArray.length;i++){
            System.out.println("参数"+(i+1)+":"+empIdArray[i]);
        }
        return empIdArray.toString();
    }

    @ResponseBody
    @RequestMapping("/send/array/plan/three.html")
    public String three(@RequestBody Integer[] empIdArray) {
        for(int i=0;i<empIdArray.length;i++){
            System.out.println("参数"+(i+1)+":"+empIdArray[i]);
        }
        return "success";
    }

    @ResponseBody
    @RequestMapping("/save/student.html")
    public String saveStudent(@RequestBody Student student){
        System.out.println("参数"+student);
        return "success";
    }
}
